/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import persistence.rb_vendor_persist;
import vo.rb_vendor;

/**
 *
 * @author subin
 */
public class VendorController {
    public static VendorController getInstance() {
        
        return new VendorController();
    }
    
    public rb_vendor create(rb_vendor vendor){
        
        return null;
    }
    
    public rb_vendor update(rb_vendor vendor){
        
        return null;
    }
    
    public List<rb_vendor> fetchAll(){
        return rb_vendor_persist.getInstance().fetch();
       
    }
    
    public Map<String,String> returnAllVendorIdAndNames() {
        
        Map<String,String> map = new HashMap<String, String>();
        List<rb_vendor> vendor=new ArrayList<rb_vendor>();
        vendor=this.fetchAll();
        Iterator it = vendor.iterator();
        while(it.hasNext()) {
            rb_vendor v=(rb_vendor)it.next();
            map.put( v.getVendor_name(),v.getVendor_id());
        }
        
        System.out.println(map);
        return map;
    }
    
    public String[] returnAllVendorNames() {
        List<rb_vendor> vendor=new ArrayList<rb_vendor>();
        vendor=this.fetchAll();
        String[] names=new String[vendor.size()];
        
        List<String> list=new ArrayList<String>();
        Iterator it=vendor.iterator();
        int cnt=0;
        while(it.hasNext()){
            rb_vendor v=(rb_vendor)it.next();
           
            names[cnt]=v.getVendor_name();
            System.out.println("----"+names[cnt]);
            cnt++;
        }
        return names;
    }
    
    public rb_vendor fetch(String vendorId){
        
        return null;
    }
    
    public String delete(rb_vendor vendor){
        
        return null;
    }
}
